import router from '../router'

export default {
	// 设置菜单
	set_menuList(state) {
		const route = router.options.routes[0].children
		let menuList = []
		route.forEach((item, index) => {
			menuList.push(item)
		})
		state.menuList = menuList
	},
	// 初始菜单标签
	start_pageTags(state) {
		const route = router.options.routes[0].children
		state.openPageList = [route[0]]
	},
	// 设置菜单标签
	set_pageTags(state, menu) {
		let obj = {
			path: menu.path,
			name: menu.name,
			meta: {
				title: menu.meta.title
			}
		}
		if (JSON.stringify(state.openPageList).indexOf(JSON.stringify(obj)) !== -1) {
			return false
		}
		state.openPageList.push(obj)
	},
	// 移除标签
	remove_tag(state, name) {
		state.openPageList.map((item, index) => {
			if (item.name === name) {
				state.openPageList.splice(index, 1)
			}
		})
	},
	// 移除其他标签
	remove_other(state, name) {
		console.log(name)
	},
	// 移除所有标签
	remove_all(state) {

	},
	// 获取到的数据
	set_data(state, data) {
		// state.result = data
		console.log(data)
		state.result = state.result.concat(data)
	},
	// 设置加载动画
	set_load(state, data) {
		state.loading = data
	},
	// 设置localStorage数据
	set_storage(state, data) {
		let arr = []
		data.forEach(item => {
			arr.push(item.serialId)
		})
		localStorage.setItem('idArray', arr)
	}
}
